import * as actionTypes from './actionTypes'
import axios from 'axios'

const changeList = (data) => ({
  type: actionTypes.CHANGE_HOME_LIST,
  data: data
})

export const getHomeList = () => {
  return (dispatch) => {
    axios.get('/api/home.json').then( res => {
      const data = res.data.data
      dispatch(changeList(data))
    }).catch((err) => {
      console.log(err)
    })
  }
}

const addActicleList = (data,page) => ({
  type: actionTypes.ADD_ACTICLELIST,
  data: data,
  page
})

export const addList = (page) => {
  return (dispatch) => {
    axios.get('/api/addList.json?page='+page).then( res => {
      const data = res.data.data
      dispatch(addActicleList(data, page+1))
    }).catch((err) => { 
      console.log(err)
    })
  }
}

export const toggleTopshow = (show) => ({
  type: actionTypes.SHOW_TOGGLE,
  show: show
}) 